using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
    /// <summary>
    /// Controller class for SiteUser
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class SiteUserController
    {
        // Preload our schema..
        SiteUser thisSchemaLoad = new SiteUser();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public SiteUserCollection FetchAll()
        {
            SiteUserCollection coll = new SiteUserCollection();
            Query qry = new Query(SiteUser.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public SiteUserCollection FetchByID(object SiteUserID)
        {
            SiteUserCollection coll = new SiteUserCollection().Where("SiteUserID", SiteUserID).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public SiteUserCollection FetchByQuery(Query qry)
        {
            SiteUserCollection coll = new SiteUserCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object SiteUserID)
        {
            return (SiteUser.Delete(SiteUserID) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object SiteUserID)
        {
            return (SiteUser.Destroy(SiteUserID) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(Guid UserID,string UserName,byte? CountryID,int? CompanyCode,string ScreenName,string Email,string Cell,string FullName,string Photo,string UnlockCode,bool Active,DateTime? ValidFrom,DateTime? ValidTo,decimal BalanceAmount,string PromotionCode,string ReferralCode,string ReferralType,int? RefUserId,DateTime DateAdded,DateTime DateModified,bool? IsLoggedIn)
	    {
		    SiteUser item = new SiteUser();
		    
            item.UserID = UserID;
            
            item.UserName = UserName;
            
            item.CountryID = CountryID;
            
            item.CompanyCode = CompanyCode;
            
            item.ScreenName = ScreenName;
            
            item.Email = Email;
            
            item.Cell = Cell;
            
            item.FullName = FullName;
            
            item.Photo = Photo;
            
            item.UnlockCode = UnlockCode;
            
            item.Active = Active;
            
            item.ValidFrom = ValidFrom;
            
            item.ValidTo = ValidTo;
            
            item.BalanceAmount = BalanceAmount;
            
            item.PromotionCode = PromotionCode;
            
            item.ReferralCode = ReferralCode;
            
            item.ReferralType = ReferralType;
            
            item.RefUserId = RefUserId;
            
            item.DateAdded = DateAdded;
            
            item.DateModified = DateModified;
            
            item.IsLoggedIn = IsLoggedIn;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(Guid UserID,int SiteUserID,string UserName,byte? CountryID,int? CompanyCode,string ScreenName,string Email,string Cell,string FullName,string Photo,string UnlockCode,bool Active,DateTime? ValidFrom,DateTime? ValidTo,decimal BalanceAmount,string PromotionCode,string ReferralCode,string ReferralType,int? RefUserId,DateTime DateAdded,DateTime DateModified,bool? IsLoggedIn)
	    {
		    SiteUser item = new SiteUser();
		    
				item.UserID = UserID;
				
				item.SiteUserID = SiteUserID;
				
				item.UserName = UserName;
				
				item.CountryID = CountryID;
				
				item.CompanyCode = CompanyCode;
				
				item.ScreenName = ScreenName;
				
				item.Email = Email;
				
				item.Cell = Cell;
				
				item.FullName = FullName;
				
				item.Photo = Photo;
				
				item.UnlockCode = UnlockCode;
				
				item.Active = Active;
				
				item.ValidFrom = ValidFrom;
				
				item.ValidTo = ValidTo;
				
				item.BalanceAmount = BalanceAmount;
				
				item.PromotionCode = PromotionCode;
				
				item.ReferralCode = ReferralCode;
				
				item.ReferralType = ReferralType;
				
				item.RefUserId = RefUserId;
				
				item.DateAdded = DateAdded;
				
				item.DateModified = DateModified;
				
				item.IsLoggedIn = IsLoggedIn;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

